﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WebCamDeskLib
{
    public partial class FrmEditList : Form
    {
        private string fFileName = String.Empty;
        private WebCamList fWebCamList;
        private WebCam fActiveCam;
        public FrmEditList()
        {
            InitializeComponent();
        }

        private void FrmEditList_Load(object sender, EventArgs e)
        {
            fWebCamList = new WebCamList("Setup.ini");
            lbCams.Items.Clear();
            foreach (WebCam myCam in fWebCamList.WebCams)
            {
                lbCams.Items.Add(myCam);
            }
        }

        private void FillEditFields(WebCam aWebCam)
        {
            edDesc.Text = aWebCam.Description;
            edAdr.Text = aWebCam.Adress;
            edPicSize.Text = aWebCam.PicSize;
            edRating.Text = aWebCam.Rating.ToString();
            edRefreshtime.Value = aWebCam.Refresh;
            edLand.Text = aWebCam.Land;
            edOrt.Text = aWebCam.Ort;
            cbDisplay.Checked = aWebCam.Active;
        }

        private void ChangeCamData(WebCam aWebCam)
        {
            aWebCam.Description = edDesc.Text;
            aWebCam.Adress = edAdr.Text;
            aWebCam.PicSize = edPicSize.Text;
            edRating.Text = aWebCam.Rating.ToString();
            aWebCam.Refresh = (int)edRefreshtime.Value;
            aWebCam.Land = edLand.Text;
            aWebCam.Ort = edOrt.Text;
            aWebCam.Active = cbDisplay.Checked;
                       
        }

        private void lbCams_SelectedValueChanged(object sender, EventArgs e)
        {
            fActiveCam = fWebCamList.GetWebCamForDesc(lbCams.SelectedItem.ToString());
            FillEditFields(fActiveCam);
        }

        private void buChange_Click(object sender, EventArgs e)
        {
            //WebCam myCam = fWebCamList.GetWebCamForDesc(lbCams.SelectedItem.ToString());
            ChangeCamData(fActiveCam);
        }

        private void buNewCam_Click(object sender, EventArgs e)
        {
            lbCams.Items.Add(fWebCamList.AddWebCam());
        }

        private void buSaveAll_Click(object sender, EventArgs e)
        {
            fWebCamList.SaveList("Setup.ini");
        }

    }
}
